package com.jie.server.modules.system.conreoller;

import com.jie.common.annotation.Log;
import com.jie.common.controller.BaseController;
import com.jie.common.enums.BusinessType;
import com.jie.common.page.TableDataInfo;
import com.jie.common.result.R;
import com.jie.server.modules.system.entity.LoginLog;
import com.jie.server.modules.system.service.ILoginLogService;
import com.jie.server.utils.ExcelUtils;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.jie.common.utils.PageUtils.startPage;

/**
 * @description: 登录日志 前端控制层
 * @author: xiaojie
 * @since: 2024/12/16 0016
 */
@Api(tags = "登录日志")
@RestController
@RequestMapping("/system/loginlog")
public class LoginLogController extends BaseController {

    @Autowired
    private ILoginLogService loginLogService;

    /**
     * 查询系统访问日志表列表
     */
    @PreAuthorize("@customSs.hasPermi('system:loginlog:list')")
    @GetMapping("/list")
    public TableDataInfo list(LoginLog loginLog) {
        startPage();
        List<LoginLog> list = loginLogService.selectLoginLogList(loginLog);
        return getDataTable(list);
    }

    /**
     * 导出系统访问日志表列表
     */
    @PreAuthorize("@customSs.hasPermi('system:loginlog:export')")
    @Log(title = "登录日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LoginLog loginLog) {
        List<LoginLog> list = loginLogService.selectLoginLogList(loginLog);
        ExcelUtils.exportEasyExcel(response,LoginLog.class,list,"系统访问日志表数据");
    }

    /**
     * 获取系统访问日志表详细信息
     */
    @PreAuthorize("@customSs.hasPermi('system:log:query')")
    @GetMapping(value = "/{loginId}")
    public R getInfo(@PathVariable("loginId") Long loginId) {
        return R.ok(loginLogService.selectLoginLogByLoginId(loginId));
    }

    /**
     * 删除系统访问日志表
     */
    @PreAuthorize("@customSs.hasPermi('system:loginlog:remove')")
    @Log(title = "登录日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{loginIds}")
    public R remove(@PathVariable Long[] loginIds) {
        return R.ok(loginLogService.deleteLoginLogByLoginIds(loginIds));
    }
    /**
     * 登录清空日志
     */
    @PreAuthorize("@customSs.hasPermi('monitor:logininfor:clean')")
    @Log(title = "登录清空日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public R clean() {
        loginLogService.cleanLoginlog();
        return R.ok();
    }

}
